<?php
class kst_display_type_model extends MY_Model {
	var $model = 'kst_display_type_model';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT  *		
					FROM	KST_DISPLAY_TYPE
					WHERE 	nama_display != '(None)' and
					(UPPER(kode_display) LIKE '%".strtoupper(post('keyword'))."%' OR 
							UPPER(nama_display) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'nama_display' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	 function Add($arr_data){
	 	$this->db->insert('kst_display_type', $arr_data);
	 }
	
	 function Update($arr_data, $arr_rule){
	 	$this->db->update('kst_display_type', $arr_data, $arr_rule);
	 }
	
	 function GetSingle($as_kode_display){
	 	$result = $this->db->get_where('kst_display_type', array('kode_display' => $as_kode_display));
	 	if($result->num_rows() == 1){
	 		return $result->row_array();
	 	}else{
	 		return NULL;
	 	}
	 }
	
	 function GetSingleView($as_kode_display)
	 {
	 	$result = $this->db->get_where('kst_display_type', array('kode_display' => $as_kode_display));
	 	if($result->num_rows() == 1){
	 		return $result->row_array();
	 	}else{
	 		return NULL;
	 	}
	 }

	 function DeleteSingle($arr_rule)
	 {
	 	try {
	 		if(	intval($this->get_data("SELECT COUNT(1) FROM kst_display_type WHERE kode_display = '".$arr_rule['kode_display']."'"))<=0)
	 		{
	 			return $this->error_delete.' [id: '.$arr_rule['kode_display']."]<br />";
	 		}else{
	 			$this->db->delete('kst_display_type', array('kode_display' => $arr_rule['kode_display']));
	 			return '';
	 		}
	 	} catch(Exception $e) {
	 		return $e->getMessage();
	 	}
	 }
}
?>